Imports DiceShenanigensUserControls

Public Class frmCreate
   Implements GridFormInterface

   Private place() As gridBox
   Private gridx As Integer = 15
   Private gridy As Integer = 15
   Private placeWidth As Integer = 35
   Private placeHeight As Integer = 35
   Private placeColor As Color
   Private placePlayer As PlayerNumber
   Private blockColor As Color = Color.Black
   Private player1Color As Color
   Private player2Color As Color
   Private player1squares As Integer
   Private player2squares As Integer

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="numPlayers"></param>
   ''' <param name="size"></param>
   ''' <param name="player1Color"></param>
   ''' <param name="player2Color"></param>
   ''' <remarks></remarks>
   Public Sub New(ByVal numPlayers As Integer, ByVal size As GridSize, ByVal player1Color As Color, ByVal player2Color As Color)

      InitializeComponent()
      playerTurn = PlayerNumber.Player1

      Me.player1Color = player1Color
      Me.player2Color = player2Color

      ' BLAH!!!
      placeColor = Me.player1Color
      placePlayer = PlayerNumber.Player1

      '' end of BLAH!!!

      gridx = size
      gridy = size

      player1squares = ((gridx * gridy) / 2)
      player2squares = ((gridx * gridy) / 2)
      player1squares += 1

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <remarks></remarks>
   Private Sub draw() Implements GridFormInterface.draw

      Dim numofplayer1 As Integer = player1squares
      Dim numofplayer2 As Integer = player2squares

      Dim c As Integer = 0



      For x As Integer = 1 To gridx
         For y As Integer = 1 To gridy

            ReDim Preserve place(c)

            place(c) = New gridBox(0, Color.White, 2, Me, gridMode.Creating)
            AddHandler place(c).boxClicked, AddressOf setColor

            place(c).Name = c
            place(c).Size = New Size(placeWidth, placeHeight)
            place(c).Location = New Point(placeWidth * (x - 1), placeHeight * (y - 1))
            gridPanel.Controls.Add(place(c))
            c += 1

         Next y
      Next x

      c -= 1
      gridPanel.Width = place(c).Right + 5
      gridPanel.Height = place(c).Bottom + 5
      'Me.Width = place(c).Right + place(c).Width + 200
      'Me.Height = place(c).Bottom + (2 * place(c).Height)

      'Me.Top = (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2) - (Me.Height / 2)
      'Me.Left = (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / 2) - (Me.Width / 2)

      'txt1Squares.BackColor = Color.Red
      'txt2Squares.BackColor = Color.Green

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub frmGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      gridPanel.Left = 15
      gridPanel.Top = 25

      draw()

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="attackerNum"></param>
   ''' <param name="defenderNum"></param>
   ''' <remarks></remarks>
   Public Sub battle(ByVal attackerNum As Integer, ByVal defenderNum As Integer) Implements GridFormInterface.battle

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public ReadOnly Property gridHeight() As Integer Implements GridFormInterface.gridHeight
      Get
         Return gridy
      End Get
   End Property

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Property reinforceStage() As Boolean Implements GridFormInterface.reinforceStage
      Get

      End Get
      Set(ByVal value As Boolean)

      End Set
   End Property

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="num"></param>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Property blackSquares(ByVal num) As Integer
      Get

      End Get
      Set(ByVal value As Integer)

      End Set
   End Property

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <value></value>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Property numReinforce() As Integer Implements GridFormInterface.numReinforce
      Get

      End Get
      Set(ByVal value As Integer)

      End Set
   End Property

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
      Application.Exit()
   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub rdoPlayer1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoPlayer1.CheckedChanged, rdoPlayer2.CheckedChanged, rdoBlock.CheckedChanged

      If rdoPlayer1.Checked Then
         placeColor = player1Color
         placePlayer = PlayerNumber.Player1
      ElseIf rdoPlayer2.Checked Then
         placeColor = player2Color
         placePlayer = PlayerNumber.Player2
      ElseIf rdoBlock.Checked Then
         placeColor = blockColor
         placePlayer = PlayerNumber.Blocked
      End If

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click

      Dim size As Integer = (gridx * gridy) - 1
      Dim owners() As Integer = Nothing
      Dim values() As Integer = Nothing

      For i As Integer = 0 To size

         ReDim Preserve owners(i)
         ReDim Preserve values(i)

         owners(i) = place(i).player
         values(i) = 0

      Next

      saveGame(owners, values, PlayerNumber.Player1)

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

      Dim game As GameGrid

      game = openGame(3)

      For i As Integer = 0 To game.Owners.Length - 1

         If game.Owners(i) = PlayerNumber.Player1 Then
            placeColor = player1Color
            placePlayer = PlayerNumber.Player1
         ElseIf game.Owners(i) = PlayerNumber.Player2 Then
            placeColor = player2Color
            placePlayer = PlayerNumber.Player2
         ElseIf game.Owners(i) = PlayerNumber.Blocked Then
            placeColor = blockColor
            placePlayer = PlayerNumber.Blocked
         End If

         place(i).playColor = placeColor
         place(i).player = placePlayer
      Next

   End Sub

   ''' <summary>
   ''' 
   ''' </summary>
   ''' <param name="index"></param>
   ''' <remarks></remarks>
   Private Sub setColor(ByVal index As Integer)
      place(index).playColor = placeColor
      place(index).player = placePlayer
   End Sub

End Class
